主题
图像文件图像分类 - YoloClassifyFromFile
函数简介
从文件做分类。
接口名称
YoloClassifyFromFileDLL 调用
long YoloClassifyFromFile(long ola, long modelHandle, string imagePath, int topK);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。 |
| modelHandle | 长整数型 | 模型句柄,任务类型须与接口一致(Detect/Classify/…) |
| imagePath | 字符串 | 图片文件路径;结果坐标相对整张图左上角 |
| topK | 整数型 | 返回得分最高的前 K 个类别(非框数);Regions[].Rank=0 为 Top-1,建议 1~10 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
auto result = ola.YoloClassifyFromFile(modelHandle, "images/scene.png", 5);
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorcsharp
using OLAPlug;
var ola = new OLAPlugServer();
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0)
{
// 模型加载失败,请检查路径与密码
}
var result = ola.YoloClassifyFromFile(modelHandle, "images/scene.png", 5);
if (result.Success)
{
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorpython
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
# 加载加密 YOLO 模型包
modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
if modelHandle == 0:
# 模型加载失败,请检查路径与密码
pass
result = ola.YoloClassifyFromFile(modelHandle, "images/scene.png", 5)
if result.Success:
# result.RegionCount 为检测框数量,result.Regions 含坐标与类别
# 完整 JSON 字段见 YOLO 推理结果说明文档
pass
# 失败时可查看 result.Errorjava
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
var result = ola.YoloClassifyFromFile(modelHandle, "images/scene.png", 5);
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorcpp
var ola = com("OlaPlug.OlaSoft")
// 加载加密 YOLO 模型包
var modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
var result = ola.YoloClassifyFromFile(modelHandle, "images/scene.png", 5)
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorvbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 加载加密 YOLO 模型包
modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
If modelHandle = 0 Then
' 模型加载失败,请检查路径与密码
End If
result = ola.YoloClassifyFromFile(modelHandle, "images/scene.png", 5)
If result.Success Then
' result.RegionCount 为检测框数量,result.Regions 含坐标与类别
' 完整 JSON 字段见 YOLO 推理结果说明文档
End If
' 失败时可查看 result.Errortext
.局部变量 ola, OLAPlug
ola.创建 ()
' 加载加密 YOLO 模型包
modelHandle = ola.YoloLoadModel(“models/yolov8n.olam“, “your_password“, 0)
.如果真 (modelHandle = 0)
' 模型加载失败,请检查路径与密码
.如果真结束
result = ola.YoloClassifyFromFile(modelHandle, “images/scene.png“, 5)
.如果真 (result.Success)
' result.RegionCount 为检测框数量,result.Regions 含坐标与类别
' 完整 JSON 字段见 YOLO 推理结果说明文档
.如果真结束
' 失败时可查看 result.Erroraardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 加载加密 YOLO 模型包
var modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
var result = ola.YoloClassifyFromFile(modelHandle, "images/scene.png", 5);
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errortext
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 加载加密 YOLO 模型包
长整数 modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
自动 result = ola.YoloClassifyFromFile(modelHandle, "images/scene.png", 5)
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorcpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
auto result = ola.YoloClassifyFromFile(modelHandle, "images/scene.png", 5);
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Error原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
// 加载加密 YOLO 模型包
long modelHandle = YoloLoadModel(instance, "models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
long resultJsonPtr = YoloClassifyFromFile(instance, modelHandle, "images/scene.png", 5);
if (resultJsonPtr != 0) {
char resultJson[512] = {0};
GetStringFromPtr(resultJsonPtr, resultJson, sizeof(resultJson));
FreeStringPtr(resultJsonPtr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
// 加载加密 YOLO 模型包
long modelHandle = YoloLoadModel(instance, "models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0)
{
// 模型加载失败,请检查路径与密码
}
long resultJsonPtr = YoloClassifyFromFile(instance, modelHandle, "images/scene.png", 5);
if (resultJsonPtr != 0) {
StringBuilder resultJson = new StringBuilder(GetStringSize(resultJsonPtr) + 1);
GetStringFromPtr(resultJsonPtr, resultJson, resultJson.Capacity);
FreeStringPtr(resultJsonPtr);
string resultJsonStr = resultJson.ToString();
}python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
# 加载加密 YOLO 模型包
modelHandle = YoloLoadModel(instance, "models/yolov8n.olam", "your_password", 0)
if modelHandle == 0:
# 模型加载失败,请检查路径与密码
pass
resultJsonPtr = YoloClassifyFromFile(instance, modelHandle, "images/scene.png", 5)
if resultJsonPtr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(resultJsonPtr, buf, 512)
ola.FreeStringPtr(resultJsonPtr)
resultJson = buf.value.decode("utf-8")返回值
长整数型:PascalCase JSON 推理结果字符串指针;失败时 Success 为 false。
注意事项
- 需要插件已开通 YOLO 模块权限(Reg、Login的FeatureList中包含YOLO特性)。
- 须为 Classify 模型;无 bbox,含 TopClassName/TopScore、Region.Rank。
- 推理入参(confidence、iou、topK、classes 等)详解见 推理输入参数说明。
- 推理结果 JSON 字段说明见 推理结果JSON说明。
- 返回的 JSON 字符串须调用 FreeStringPtr 释放。
本接口关键参数
| 参数 | 作用摘要 |
|---|---|
topK | 返回 Top-K 个分类结果(按 Score 排序),无 bbox |
Classify 无 confidence / iou。详见 推理输入参数说明。
